REM Convert the output from a star command into a menu
REM Syntax: CommMenu [-c|-command] <command> [-t|-title <title>]

REM Title:      Director:Menus.System.CommMenu
REM Author:     Philip Ludlam
REM Version:    0.70, Monday the 28th of April, 2003
REM Copyright:  (C) Philip Ludlam 2003

REM This program is free software; you can redistribute it and/or modify it
REM under the terms of the GNU General Public License as published by the Free
REM Software Foundation; either version 2 of the License, or (at your option)
REM any later version.
REM
REM This program is distributed in the hope that it will be useful, but WITHOUT
REM ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
REM FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more
REM details.
REM
REM You should have received a copy of the GNU General Public License along with
REM this program; if not, write to the Free Software Foundation, Inc., 59 Temple
REM Place - Suite 330, Boston, MA 02111-1307, USA

file%=0:ON ERROR PROCerror
DIM block% 1023

SYS "OS_GetEnv" TO comm%
SYS "OS_ReadArgs","name,quit,command/c,title/t",comm%,block%,1023
comm$=FNstring(block%!8)
IF block%!12<>0 title$=FNstring(block%!12) ELSE title$=comm$
OSCLI(comm$+" { > <Wimp$ScrapDir>.Director.CommMenu }")

file%=OPENIN("<Wimp$ScrapDir>.Director.CommMenu")

SYS "Director_Menu",""""+title$+""" CommMenu -temp"

WHILE NOT EOF#file%
  text$=FNread
  IF text$<>"" SYS "Director_Option",""""+text$+""""
ENDWHILE

SYS "Director_EndMenu"
CLOSE#file%:file%=0

OSCLI("Set Director$Menu CommMenu")

END

:

DEF FNread:LOCAL text$:text$=""
WHILE text$="" AND NOT EOF#file%
  chr%=BGET#file%
  WHILE chr%>=32 AND NOT EOF#file%
    IF CHR$(chr%)="<" text$+="|"
    IF CHR$(chr%)="""" text$+=""""
    IF CHR$(chr%)="|" text$+="|"
    text$+=CHR$(chr%)
    chr%=BGET#file%
  ENDWHILE
ENDWHILE
=text$

:

DEF FNstring(ptr%):LOCAL a$:a$=""
WHILE ?ptr%>31
  a$+=CHR$(?ptr%):ptr%+=1
  ENDWHILE:=a$

:

DEF PROCerror
ON ERROR OFF
IF file%<>0 CLOSE#file%
VDU 4
PRINT "Error in: !Director.Menus.System.CommMenu"
PRINT "Report:   ";REPORT$
PRINT "Line:     ";ERL
END

:
